// 验证码服务
// author : Xavier
package service

import (
	"admin_go_api/common/util"
	"image/color"

	"github.com/mojocn/base64Captcha"
)

var store = util.RedisStore{}

// 生成验证码
func CaptMake() (id, b64s string) {
	var driver base64Captcha.Driver
	var driverString base64Captcha.DriverString
	//配置验证码信息
	capychaConfig := base64Captcha.DriverString{
		Height:          60,
		Width:           240,
		NoiseCount:      0,
		ShowLineOptions: 2 | 4,
		Length:          6,
		Source:          "1234567890abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ",
		BgColor: &color.RGBA{
			R: 3,
			G: 102,
			B: 214,
			A: 125,
		},
		Fonts: []string{"wqy-microhei.ttc"},
	}
	driverString = capychaConfig
	driver = driverString.ConvertFonts()
	captcha := base64Captcha.NewCaptcha(driver, store)
	id, b64s, _ = captcha.Generate()
	return id, b64s
}

// 验证验证码
func CaptVerify(id, answer string) bool {
	return store.Verify(id, answer, true)
}
